﻿/*
Author: yang_wanjun
Create: 2011/05/12
Update: 2011/05/12
 */

// 检查是否为空
Validator.prototype.is_empty = function(obj_id, message) {
	var obj = document.getElementById(obj_id);
	if (obj != null) {
		if (obj.value == "") {
			if (message == null)
				message = "存在未输入项！";
			alert(message + "是必须项，请输入！");
			return false;
		}
	}
	return true;
}

// 检查是否为电子邮件
Validator.prototype.is_email = function(obj_id, is_required) {
	var obj = document.getElementById(obj_id);
	if (obj != null) {
		if (is_required || obj.value != "") {
			var match_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
			if (!match_str.test(obj.value)) {
				alert('请输入正确的邮件地址！');
				return false;
			}
			return true;
		}
	}
	return true;
}

// 检查评论是否填写正确
Validator.prototype.check_comment = function(name_id, email_id, comment_id) {
	return (this.is_empty(name_id, "名称") && this.is_email(email_id, true) && this
			.is_empty(comment_id, "评论内容"));
}